home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / Xsun / sunIo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-25  |  7.3 KB  |  274 lines

  1. /*-
  2.  * sunIo.c --
  3.  *    Functions to handle input from the keyboard and mouse.
  4.  *
  5.  * Copyright (c) 1987 by the Regents of the University of California
  6.  *
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  *
  16.  */
  17.  
  18. /************************************************************
  19. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  20.  
  21.                     All Rights Reserved
  22.  
  23. Permission  to  use,  copy,  modify,  and  distribute   this
  24. software  and  its documentation for any purpose and without
  25. fee is hereby granted, provided that the above copyright no-
  26. tice  appear  in all copies and that both that copyright no-
  27. tice and this permission notice appear in  supporting  docu-
  28. mentation,  and  that the names of Sun or MIT not be used in
  29. advertising or publicity pertaining to distribution  of  the
  30. software  without specific prior written permission. Sun and
  31. M.I.T. make no representations about the suitability of this
  32. software for any purpose. It is provided "as is" without any
  33. express or implied warranty.
  34.  
  35. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  36. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  37. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  38. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  39. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  40. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  41. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  42. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  43.  
  44. ********************************************************/
  45.  
  46. #ifndef    lint
  47. static char sccsid[] = "%W %G Copyright 1987 Sun Micro";
  48. #endif
  49.  
  50. #include    "sun.h"
  51. #include    "opaque.h"
  52. #include    <sys/time.h>
  53.  
  54. int            lastEventTime = 0;
  55. extern int    spriteCheckInput;
  56. extern int      screenIsSaved;
  57. extern void    SaveScreens();
  58.  
  59. extern unsigned int    repeatLong, repeatShort;
  60.  
  61. /*-
  62.  *-----------------------------------------------------------------------
  63.  * sunInputAvail --
  64.  *    This function is called from the scheduler whenever one of
  65.  *    the devices we told it to look for has input waiting.
  66.  *
  67.  * Results:
  68.  *    None.
  69.  *
  70.  * Side Effects:
  71.  *    spriteCheckInput has its READ_INPUT flag set.
  72.  *
  73.  *-----------------------------------------------------------------------
  74.  */
  75. void
  76. sunInputAvail()
  77. {
  78.     spriteCheckInput = 1;
  79. }
  80.  
  81. /*-
  82.  *-----------------------------------------------------------------------
  83.  * TimeSinceLastInputEvent --
  84.  *    Function used for screensaver purposes by the os module.
  85.  *
  86.  * Results:
  87.  *    The time in milliseconds since there last was any
  88.  *    input.
  89.  *
  90.  * Side Effects:
  91.  *    None.
  92.  *
  93.  *-----------------------------------------------------------------------
  94.  */
  95. int
  96. TimeSinceLastInputEvent()
  97. {
  98.     struct timeval    now;
  99.  
  100.     gettimeofday (&now, (struct timezone *)0);
  101.  
  102.     if (lastEventTime == 0) {
  103.     lastEventTime = TVTOMILLI(now);
  104.     }
  105.     return TVTOMILLI(now) - lastEventTime;
  106. }
  107.  
  108. /*-
  109.  *-----------------------------------------------------------------------
  110.  * ProcessInputEvents --
  111.  *    Retrieve all waiting input events and pass them to DIX in their
  112.  *    correct chronological order. Only reads from the system pointer
  113.  *    and keyboard.
  114.  *
  115.  * Results:
  116.  *    None.
  117.  *
  118.  * Side Effects:
  119.  *    Events are passed to the DIX layer.
  120.  *
  121.  *-----------------------------------------------------------------------
  122.  */
  123. void
  124. ProcessInputEvents ()
  125. {
  126.     register Mouse_Event    *events;         /* Array of events */
  127.     register int          numEvents;        /* Number of events left */
  128.     int                      nE;                /* Total number of events */
  129.     DevicePtr            pPointer;        /* System pointer */
  130.     DevicePtr            pKeyboard;        /* System keyboard */
  131.     register PtrPrivPtr     ptrPriv;        /* Private data for pointer */
  132.     register KbPrivPtr        kbdPriv;        /* Private data for keyboard */
  133.     Mouse_Event          *lastEvent;        /* Last event processed */
  134.     enum {
  135.     NoneYet, Ptr, Kbd
  136.     }                lastType = NoneYet;    /* Type of last event */
  137.  
  138.     pPointer = LookupPointerDevice();
  139.     pKeyboard = LookupKeyboardDevice();
  140.     
  141.     ptrPriv = (PtrPrivPtr)pPointer->devicePrivate;
  142.     kbdPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  143.     
  144.     /*
  145.      * Get events from both the pointer and the keyboard via the keyboard's
  146.      * GetEvents vector. The number of events read is stored in numEvents.
  147.      */
  148.     events = (* kbdPriv->GetEvents) (pKeyboard, &nE);
  149.     numEvents = nE;
  150.     
  151.     while (numEvents) {
  152.     if (events->flags & KEYBOARD_EVENT) {
  153.         if (lastType == Ptr) {
  154.             (* ptrPriv->DoneEvents) (pPointer, FALSE);
  155.             lastType = Kbd;
  156.         }
  157.         (* kbdPriv->ProcessEvent) (pKeyboard, events);
  158.     } else if (events->flags & MOUSE_EVENT) {
  159.         if (lastType == Kbd) {
  160.             (* kbdPriv->DoneEvents) (pKeyboard, FALSE);
  161.             lastType = Ptr;
  162.         }
  163.         (* ptrPriv->ProcessEvent) (pPointer, events);
  164.     } else {
  165.         /* ??? */
  166.     }
  167.     lastEvent = events;
  168.     lastEventTime = events->time;
  169.     numEvents -= 1;
  170.     events += 1;
  171.     }
  172.     
  173.     SetTimeSinceLastInputEvent();
  174.     if (lastEvent) {
  175.     if (screenIsSaved == SCREEN_SAVER_ON) {
  176.         SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
  177.     }
  178.     }
  179.     
  180.     (* kbdPriv->DoneEvents) (pKeyboard, TRUE);
  181.     (* ptrPriv->DoneEvents) (pPointer, TRUE);
  182.  
  183.     spriteCheckInput = 0;
  184. }
  185.  
  186.  
  187. /*-
  188.  *-----------------------------------------------------------------------
  189.  * SetTimeSinceLastInputEvent --
  190.  *    Set the lastEventTime to now.
  191.  *
  192.  * Results:
  193.  *    None.
  194.  *
  195.  * Side Effects:
  196.  *    lastEventTime is altered.
  197.  *
  198.  *-----------------------------------------------------------------------
  199.  */
  200. void
  201. SetTimeSinceLastInputEvent()
  202. {
  203.     struct timeval now;
  204.  
  205.     gettimeofday (&now, (struct timezone *)0);
  206.     lastEventTime = TVTOMILLI(now);
  207. }
  208.  
  209. /*
  210.  * DDX - specific abort routine.  Called by AbortServer().
  211.  */
  212. void
  213. AbortDDX()
  214. {
  215.     sunNonBlockConsoleOff ((char *) 0);
  216. }
  217.  
  218. /* Called by GiveUp(). */
  219. void
  220. ddxGiveUp()
  221. {
  222. }
  223.  
  224. int
  225. ddxProcessArgument (argc, argv, i)
  226.     int    argc;
  227.     char *argv[];
  228.     int    i;
  229. {
  230.     extern void UseMsg();
  231.     extern Bool ActiveZaphod;
  232.  
  233.     if (strcmp (argv[i], "-ar1") == 0) {    /* -ar1 int */
  234.     if (++i >= argc) UseMsg ();
  235.     repeatLong = 1000 * (long)atoi(argv[i]);
  236.     return 2;
  237.     }
  238.     if (strcmp (argv[i], "-ar2") == 0) {    /* -ar2 int */
  239.     if (++i >= argc) UseMsg ();
  240.     repeatShort = 1000 * (long)atoi(argv[i]);
  241.     return 2;
  242.     }
  243. #ifndef    sprite
  244.     if (strcmp (argv[i], "-debug") == 0) {    /* -debug */
  245.     return 1;
  246.     }
  247. #endif    sprite
  248.     if (strcmp (argv[i], "-dev") == 0) {    /* -dev /dev/mumble */
  249.     if (++i >= argc) UseMsg ();
  250.     return 2;
  251.     }
  252.     if (strcmp (argv[i], "-mono") == 0) {    /* -mono */
  253.     return 1;
  254.     }
  255.     if (strcmp (argv[i], "-zaphod") == 0) {    /* -zaphod */
  256.     ActiveZaphod = FALSE;
  257.     return 1;
  258.     }
  259.     return 0;
  260. }
  261.  
  262. void
  263. ddxUseMsg()
  264. {
  265.     ErrorF("-ar1 int               set autorepeat initiate time\n");
  266.     ErrorF("-ar2 int               set autorepeat interval time\n");
  267. #ifndef    sprite
  268.     ErrorF("-debug                 disable non-blocking console mode\n");
  269.     ErrorF("-dev filename          name of device to open\n");
  270. #endif    sprite
  271.     ErrorF("-mono                  force monochrome-only screen\n");
  272.     ErrorF("-zaphod                disable active Zaphod mode\n");
  273. }
  274.